package com.cch.cooperation.common.web.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 响应数据
 *
 * @author cch
 */
@ApiModel("响应参数")
@Data
public class Response<T> {

    @ApiModelProperty("状态码")
    private Integer statusCode;

    @ApiModelProperty("操作提示")
    private String message;

    @ApiModelProperty("状态（成功:1，失败:0）")
    private Integer status;

    @ApiModelProperty("数据")
    private T data;

    public static final Integer STATUS_OK = 1;
    public  static final Integer STATUS_FAIL = 0;

    public static Response<Void> success(String message) {
        return success(200, message, null);
    }

    public static <T> Response<T> success(T data) {
        return success(200, "操作成功", data);
    }

    public static <T> Response<T> success(String message, T data) {
        return success(200, message, data);
    }

    public static <T> Response<T> success(Integer statusCode, String message, T data) {
        Response<T> response = new Response<>();
        response.setStatus(STATUS_OK);
        response.setStatusCode(statusCode);
        response.setData(data);
        response.setMessage(message);
        return response;
    }

    public static <T> Response<T> success() {
        return success(200, "操作成功", null);
    }

    public static <T> Response<T> fail(String message) {
        return fail(message, 500, null);
    }

    public static <T> Response<T> fail(String message, Integer statusCode) {
        return fail(message, statusCode, null);
    }

    public static <T> Response<T> fail(String message, Integer statusCode, T data) {
        Response<T> response = new Response<>();
        response.setStatus(STATUS_FAIL);
        response.setData(data);
        response.setMessage(message);
        response.setStatusCode(statusCode);
        return response;
    }
}
